﻿using DevExpress.XtraEditors;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;

namespace BACKOFFICE
{
    [Serializable]
    public class SaveLoadXMLSeattingChart
    {

        public static List<Control> buttons = new List<Control>();

        //[Serializable]
        public class ButtonPropertys
        {
            public string Text { get; set; }
            public int Width { get; set; }
            public int Height { get; set; }
            public Point Location { get; set; }

        }

        public static void WriteToXml()
        {

            using (XmlWriter writer = XmlWriter.Create("SeatingChart.xml"))
            {
                writer.WriteStartDocument();
                writer.WriteStartElement("BUTTON");

                foreach (Control controls in buttons)
                {
                    writer.WriteStartElement("SimpleButton");

                    //writer.WriteElementString("Name", controls.Name);
                    writer.WriteElementString("Text", controls.Text);
                    writer.WriteElementString("Width", controls.Width.ToString());
                    writer.WriteElementString("Height", controls.Height.ToString());

                    ////writer.WriteStartElement("Location");
                    writer.WriteElementString("X", controls.Location.X.ToString());
                    writer.WriteElementString("Y", controls.Location.Y.ToString());
                    ////writer.WriteEndElement();

                    writer.WriteEndElement();
                }

                writer.WriteEndElement();
                writer.WriteEndDocument();
            }
        }
    }

    public class ReadXMLSeattingChart
    {
        public static SimpleButton testing = new SimpleButton();

        [XmlRoot(ElementName = "BUTTON")]
        public class Buttons
        {
            [XmlElement(ElementName = "SimpleButton")]
            public string text;
            public Int32 width;
            public Int32 height;
            public int LocationX;
            public int LocationY;
        }

        public static void ReadXML()
        {
            System.Xml.Serialization.XmlSerializer reader = new System.Xml.Serialization.XmlSerializer(typeof(Buttons));
            System.IO.StreamReader file = new System.IO.StreamReader("SeatingChart.xml");

            Buttons buttons = new Buttons();
            buttons = (Buttons)reader.Deserialize(file);

            testing.Text = buttons.text;
            testing.Width = 75;// buttons.width;
            testing.Height = 75;// buttons.height;
            testing.Location = new Point(buttons.LocationX, buttons.LocationY);


            MessageBox.Show(buttons.text + "    " + buttons.LocationX.ToString() + "     " + buttons.LocationY.ToString());
        }
    }
}
